<template>
  <view class="page-resumeitem">
    <view class="page-resumeitem-name">
      <view class="f-16 flex-row align-items-center" v-if="!isEdit">
        <view >{{ data.alias ? data.alias : '简历名称未填写' }}</view>
        <view class="ml-8 page-resumeitem-nameicon" @click="isEdit = !isEdit"></view> 
      </view>
      <view v-if="isEdit" class="flex-row align-items-center">
        <view class="flex-1">
          <pk-input v-model="data.tempalias" :placeholder="data.tempalias || '请输入简历名称'"></pk-input>
        </view>
        <view class="ml-12 flex-row align-items-center">
          <view><pk-btn size="mini" type="danger" @click="saveCloseEdit">取消</pk-btn></view>
          <view class="ml-12"><pk-btn size="mini" type="success" @click="saveEdit">保存</pk-btn></view> 
        </view>
      </view>
    </view>
    <view class="f-12 mt-8 gray-color6">上传时间：{{ data.created_at }}</view>
    <view class="page-resumeitem-divider"></view>
    <view class="page-resumeitem-footer flex-row space-between align-items-center">
      <!-- <view class="page-resumeitem-default gray-color flex-row align-items-center">
        <text v-if="data.default" class="f-12">默认简历</text>
      </view> -->
      <view class="base-color f-12 mr-12">
        <!-- <pk-btn size="mini" v-if="!data.default" @click="setDefault">设置默认</pk-btn>
        <pk-btn size="mini" v-if="data.default" >默认简历</pk-btn> -->
      </view>
      <view class="page-resumeitem-btnbox flex-row">
        <view class="base-color f-12 mr-12" @click="setview">
          <pk-btn size="mini">点击浏览</pk-btn>
        </view> 
        <view class="base-color f-12 mr-12">
          <pk-btn size="mini" v-if="!data.default" @click="setDefault">设置默认</pk-btn>
          <pk-btn size="mini" type="success" v-if="data.default" >默认简历</pk-btn>
        </view>
        <view class="base-color f-12" @click="setDeleteItem">
          <pk-btn size="mini" type="danger">删除</pk-btn>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { defineProps, defineEmits, ref } from 'vue';
import { attachmentSetDefault, attachmentDelete, attachmentEdit } from '@/api/api'
const emits = defineEmits(['ontrue', 'onfalse'])
const props = defineProps({
  data: {
    type: Object,
    default: () => {}
  }
})

const isEdit = ref(false)

//保存
const  saveEdit = () => {
  attachmentEdit({
    attachment_id: props.data.attachment_id,
    alias: props.data.tempalias
  }).then(res => {
    isEdit.value = false
    emits('onEdit', props.data.tempalias)
  })
}

const saveCloseEdit = (e) => {
  isEdit.value = false
  emits('onEdit', props.data.alias)
}

const setview = () => {
  uni.navigateTo({
    url: '/pages/pdfview/index?weburl=' + encodeURIComponent(props.data.source_link)
  });
}

const setDefault = () => {
  attachmentSetDefault({
    attachment_id: props.data.attachment_id
  }).then(res => {
    emits('ontrue', props.data.attachment_id)
  })
}

const setDetelePost = () => {
  attachmentDelete({
    attachment_id: props.data.attachment_id
  }).then(res => {
    emits('onDelete')
  })
}

const setDeleteItem = () => {
  uni.showModal({
    title: '提示',
    content: '确认要删除?',
    success: function (res) {
      if (res.confirm) {
        setDetelePost()
      }
    }
  });
}
</script>

<style lang="scss" scoped>
.page-resumeitem{
  background: #fff;
  border-radius: 16rpx;
  padding: 32rpx;
  &-footerfile{
    display: flex;
    flex-direction: row;
  }
  &-footerfileicon{
    width: 30rpx;
    height: 44rpx;
    background: url("@/static/fileicon.png") center center no-repeat;
    background-size: 30rpx auto;
    border-radius: 44rpx;
  }
  &-nameicon{
    width: 44rpx;
    height: 44rpx;
    background: url("@/static/eidticon.png") center center no-repeat;
    background-size: 28rpx auto;
  }
  &-footerfilebtn{
    display: flex;
    border-radius: 32rpx;
    border:#ebebeb 1px solid;
    height: 44rpx;
    line-height: 44rpx;
    padding: 0 16rpx;
  }
  &-divider{
    width:100%;
    height: 1px;
    background: #ebebeb;
    margin:24rpx 0;
    transform: scaleY(0.5);
  }
  &-footer{
    font-size: 24rpx;
  }
  &-default{
    width: 200rpx;
  }
}
</style>